<?php
require_once("../application.php");
require_once(ROOT_DIR."/classes/LSync.class.php");

$web = $_REQUEST["web"];
// TODO 加个回调地址验证码
if($web == null) die("request error");

$ret = false;
$user_id = isset($_SESSION['user'])?$_SESSION['user']['user_id']:null;
if("sina"==$web){
	$keys = $_SESSION['keys'] or die("no oauth_token");
	$ret = LSync::Login($user_id, $web, $keys['oauth_token'], $keys['oauth_token_secret']);
}else if('renren'==$web) {
	$ret = LSync::Login($user_id, $web);
} else{
	echo "unknow login method!";
}
if($ret){
	if($_SESSION['url_before_login']){
		header("Location: {$_SESSION['url_before_login']}");
	}else {
		$url = ROOT_URL."index.php";
		header("Location: {$url}");
	}
}